package cn.itcast.zt;

import cn.hutool.http.HttpRequest;

import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Semaphore;

/**
 * create by zhangtian105 on 2020/10/6
 */
public class MultiThreadDemoTest {

    // 同时并发执行的线程数
    public static int threadTotal =  100 ;

    public static void main(String[] args) throws Exception {
        //for (;;) {
            ExecutorService service = Executors.newCachedThreadPool() ;
            final Semaphore semaphore = new Semaphore(threadTotal) ;
            // 执行次数
            final CountDownLatch countDownLatch = new CountDownLatch(1000) ;
            for(int i = 0; i < 1000; i++){
                int finalI = i;
                service.execute(()->{
                    try {
                        semaphore.acquire();
                        add(finalI) ;
                        semaphore.release();
                    } catch (InterruptedException e) {
                        System.out.println("exception ......");
                    }
                    countDownLatch.countDown();
                });
            }

            countDownLatch.await();
            service.shutdown();
       // }
    }

    private static void add(int times) {
        /*String result = HttpRequest.get("http://zdmbeta.m.jd.care/discZdmGoodsList?functionId=discZdmGoodsList&client=android&openudid=705ad791fe629d97&uuid=705ad791fe629d97&clientVersion=9.5.2&pin=jd_4add1febcc94d")
                .body("body={\"channel\":\"worthbuy\",\"page\":1,\"pageSize\":15,\"params\":{\"channel\":\"home\",\"innerIndex\":2,\"innerLink\":\"[{\\\"rt\\\":\\\"12\\\",\\\"innerAnchor\\\":\\\"55381630878\\\",\\\"innerExtId\\\":\\\"220995144\\\"},{\\\"rt\\\":\\\"12\\\",\\\"innerAnchor\\\":\\\"59466133728\\\",\\\"innerExtId\\\":\\\"226825400\\\"}]\",\"innerSkuImgUrl\":\"https://m.360buyimg.com/mobilecms/s240x240_jfs/t1/58436/7/13440/361385/5da53fd5E2428e6de/0f76917c8cc2a4cf.png!q70.jpg\"},\"sids\":\"\",\"subPosition\":\"-1\",\"tabId\":\"229\",\"type\":\"goods\"}")
                .cookie("pin=jd_4add1febcc94d;wskey=AAJgYrpbAEA-BkUSHQvz3yk9lUWfGtUioy25mAcf1NGV8W8QpUXGcj2ne6sGMeKRXvjcyeEfnyuIw5FaIawK0KIFt4umP_a9;whwswswws=zL+687hjUYtAwqjbO81RFUuSKr3DWVHXllHWwZF3nizj85CzwXALBhiHoo03vCQdQ0k72z4Fzrmut376UQTLHDA==;unionwsws={\"devicefinger\":\"eidAb7398121fdscd431fUM2Q4mtJv+Qdfp5RHeN9vXE3VvyJyaGXU0m10CFGMBU\\/LSMfjBjHlp75gzxz8EOslp5HWpSaoqRHDWxRM6frpDKiJj5KclR\",\"jmafinger\":\"zL+687hjUYtAwqjbO81RFUuSKr3DWVHXllHWwZF3nizj85CzwXALBhiHoo03vCQdQ0k72z4Fzrmut376UQTLHDA==\"}")
                .execute()
                .body();*/

        String result = HttpRequest.get("http://127.0.0.1:8000/user/putHashMapTest?times="+times)
                .execute()
                .body();

        System.out.println("result:" + result);
    }
}